package generator.model;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

public class SideOfferGenerator extends AbstractGenerator {

	private List<String> offerItems;
	private List<String> offerSlogans;
	
	
	public SideOfferGenerator() {
		offerItems = new ArrayList<String>();
		
		offerSlogans = new ArrayList<String>();
	}
	
	public SideOfferGenerator(String filename) {
		
		offerItems = new ArrayList<String>();
		offerSlogans = new ArrayList<String>();
		
		try {
			HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(filename));
			
			HSSFSheet s = wb.getSheet("SidoPrylar");
			
			for(int r=s.getFirstRowNum(); r<=s.getLastRowNum(); r++) {
				HSSFRow row = s.getRow(r);
				
				HSSFCell cell = row.getCell(0);				
				if(cell!=null) {
					offerItems.add(cell.getStringCellValue());
				}
				
				cell = row.getCell(1);
				if(cell!=null) {
					offerSlogans.add(cell.getStringCellValue());
				}
			}
			
			
			
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public String getOfferItem() {		
		return getRandom(offerItems);
	}

	public String getOfferSlogan() {
		return getRandom(offerSlogans);
	}

}
